home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / sys / vnode.h < prev    next >
Text File  |  1995-02-14  |  9KB  |  268 lines

  1. /* @(#)vnode.h    2.4 88/06/13 4.0NFSSRC SMI; from SMI 2.34 87/12/04    */
  2. /*
  3.  * HISTORY
  4.  * 24-Oct-91  Joe Murdock (jmurdock) at NeXT
  5.  *    #ifdef'd file to avoid #include conflicts
  6.  *
  7.  * 27-Sep-89  Morris Meyer (mmeyer) at NeXT
  8.  *    NFS 4.0 Changes: added vn_dump, vn_cmp and vn_realvp to vnodeops.
  9.  *             added parameters to VOP_CLOSE and VOP_LOOKUP.
  10.  *
  11.  *  9-Sep-87  Peter King (king) at NeXT
  12.  *    Added pager_id;
  13.  *
  14.  * 19-Aug-87  Peter King (king) at NeXT
  15.  *    Added v_text pointer to associated text block.
  16.  */
  17.  
  18. #ifndef _VNODE_H_
  19. #define _VNODE_H_
  20.  
  21. #if    KERNEL
  22. #import <vm/vm_pager.h>         // pager_return_t
  23. #else    KERNEL
  24. typedef int pager_return_t;
  25. #endif    KERNEL
  26. #import <sys/time.h>
  27.  
  28. /*
  29.  * The vnode is the focus of all file activity in UNIX.
  30.  * There is a unique vnode allocated for each active file,
  31.  * each current directory, each mounted-on file, text file, and the root.
  32.  */
  33.  
  34. /*
  35.  * vnode types. VNON means no type.
  36.  */
  37. enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VBAD, VFIFO, VSTR };
  38.  
  39. struct vnode {
  40.     struct vm_info    *vm_info;    /* pointer to VM info structure */
  41.     u_short        v_flag;            /* vnode flags (see below)*/
  42.     u_short        v_count;        /* reference count */
  43.     u_short        v_shlockc;        /* count of shared locks */
  44.     u_short        v_exlockc;        /* count of exclusive locks */
  45.     struct vfs    *v_vfsmountedhere;     /* ptr to vfs mounted here */
  46.     struct vfs    *v_vfsentries;        /* fake entries for mounts */
  47.     struct timeval    v_vfstime;        /* time of last mount change */
  48.     struct vnodeops    *v_op;            /* vnode operations */
  49.     union {
  50.         struct socket    *v_Socket;    /* unix ipc */
  51.         struct stdata    *v_Stream;    /* stream */
  52.     } v_s;
  53.     struct vfs    *v_vfsp;        /* ptr to vfs we are in */
  54.     enum vtype    v_type;            /* vnode type */
  55.     dev_t        v_rdev;            /* device (VCHR, VBLK) */
  56.     caddr_t        v_data;            /* private data for fs */
  57. #if    MACH
  58. #else
  59.     struct text    *v_text;        /* text entry (if any) */
  60. #endif    MACH
  61. };
  62. #define    v_stream    v_s.v_Stream
  63. #define    v_socket    v_s.v_Socket
  64.  
  65. /*
  66.  * vnode flags.
  67.  */
  68. #define    VROOT        0x01    /* root of its file system */
  69. #define VTEXT        0x02    /* vnode is a pure text prototype */
  70. #define    VEXLOCK        0x04    /* exclusive lock */
  71. #define    VSHLOCK        0x08    /* shared lock */
  72. #define    VLWAIT        0x10    /* proc is waiting on shared or excl. lock */
  73. #define    VTEXTMOD    0x20    /* text has been modified (e.g. ptrace) */
  74. #define    VNOCACHE    0x40    /* don't keep cache pages on vnode */
  75. #define    VISSWAP        0x80    /* vnode is part of virtual swap device */
  76.  
  77. /*
  78.  * Operations on vnodes.
  79.  */
  80. struct vnodeops {
  81.     int    (*vn_open)();
  82.     int    (*vn_close)();
  83.     int    (*vn_rdwr)();
  84.     int    (*vn_ioctl)();
  85.     int    (*vn_select)();
  86.     int    (*vn_getattr)();
  87.     int    (*vn_setattr)();
  88.     int    (*vn_access)();
  89.     int    (*vn_lookup)();
  90.     int    (*vn_create)();
  91.     int    (*vn_remove)();
  92.     int    (*vn_link)();
  93.     int    (*vn_rename)();
  94.     int    (*vn_mkdir)();
  95.     int    (*vn_rmdir)();
  96.     int    (*vn_readdir)();
  97.     int    (*vn_symlink)();
  98.     int    (*vn_readlink)();
  99.     int    (*vn_fsync)();
  100.     int    (*vn_inactive)();
  101.     int    (*vn_bmap)();
  102.     int    (*vn_strategy)();
  103.     int    (*vn_bread)();
  104.     int    (*vn_brelse)();
  105.     int    (*vn_lockctl)();
  106.     int    (*vn_fid)();
  107.     int    (*vn_dump)();
  108.     int    (*vn_cmp)();
  109.     int    (*vn_realvp)();
  110.     pager_return_t    (*vn_pagein)();
  111.     pager_return_t    (*vn_pageout)();
  112.     int    (*vn_nlinks)();
  113. #if    NeXT
  114.     int    (*vn_devblocksize)();
  115.     pager_return_t    (*vn_prepagein)();
  116.     pager_return_t    (*vn_apageout)();
  117. #endif    NeXT
  118. };
  119.  
  120. #ifdef KERNEL
  121.  
  122. #define VOP_OPEN(VPP,F,C)        (*(*(VPP))->v_op->vn_open)(VPP, F, C)
  123. #define VOP_CLOSE(VP,F,C,CR)        (*(VP)->v_op->vn_close)(VP,F,C,CR)
  124. #define VOP_RDWR(VP,UIOP,RW,F,C)    (*(VP)->v_op->vn_rdwr)(VP,UIOP,RW,F,C)
  125. #define VOP_IOCTL(VP,C,D,F,CR)        (*(VP)->v_op->vn_ioctl)(VP,C,D,F,CR)
  126. #define VOP_SELECT(VP,W,C)        (*(VP)->v_op->vn_select)(VP,W,C)
  127. #define VOP_GETATTR(VP,VA,C)        (*(VP)->v_op->vn_getattr)(VP,VA,C)
  128. #define VOP_SETATTR(VP,VA,C)        (*(VP)->v_op->vn_setattr)(VP,VA,C)
  129. #define VOP_ACCESS(VP,M,C)        (*(VP)->v_op->vn_access)(VP,M,C)
  130. #define VOP_LOOKUP(VP,NM,VPP,C,PN,F)    (*(VP)->v_op->vn_lookup)(VP,NM,VPP,C,PN,F)
  131. #define VOP_CREATE(VP,NM,VA,E,M,VPP,C)    (*(VP)->v_op->vn_create) \
  132.                         (VP,NM,VA,E,M,VPP,C)
  133. #define VOP_REMOVE(VP,NM,C)        (*(VP)->v_op->vn_remove)(VP,NM,C)
  134. #define VOP_LINK(VP,TDVP,TNM,C)        (*(TDVP)->v_op->vn_link)(VP,TDVP,TNM,C)
  135. #define VOP_RENAME(VP,NM,TDVP,TNM,C)    (*(VP)->v_op->vn_rename) \
  136.                         (VP,NM,TDVP,TNM,C)
  137. #define VOP_MKDIR(VP,NM,VA,VPP,C)    (*(VP)->v_op->vn_mkdir)(VP,NM,VA,VPP,C)
  138. #define VOP_RMDIR(VP,NM,C)        (*(VP)->v_op->vn_rmdir)(VP,NM,C)
  139. #define VOP_READDIR(VP,UIOP,C)        (*(VP)->v_op->vn_readdir)(VP,UIOP,C)
  140. #define VOP_SYMLINK(VP,LNM,VA,TNM,C)    (*(VP)->v_op->vn_symlink) \
  141.                         (VP,LNM,VA,TNM,C)
  142. #define VOP_READLINK(VP,UIOP,C)        (*(VP)->v_op->vn_readlink)(VP,UIOP,C)
  143. #define VOP_FSYNC(VP,C)            (*(VP)->v_op->vn_fsync)(VP,C)
  144. #define VOP_INACTIVE(VP,C)        (*(VP)->v_op->vn_inactive)(VP,C)
  145. #define VOP_LOCKCTL(VP,LD,CMD,C,ID)    (*(VP)->v_op->vn_lockctl) \
  146.                         (VP,LD,CMD,C,ID)
  147. #define VOP_BMAP(VP,BN,VPP,BNP)        (*(VP)->v_op->vn_bmap)(VP,BN,VPP,BNP)
  148. #define VOP_BREAD(VP,BN,BPP)        (*(VP)->v_op->vn_bread)(VP,BN,BPP)
  149. #define VOP_BRELSE(VP,BP)        (*(VP)->v_op->vn_brelse)(VP,BP)
  150. #define VOP_FID(VP, FIDPP)        (*(VP)->v_op->vn_fid)(VP, FIDPP)
  151. #define VOP_DUMP(VP, ADDR, BN, CT)    (*(VP)->v_op->vn_dump)(VP, ADDR, BN, CT)
  152. #define VOP_CMP(VP1, VP2)        (*(VP1)->v_op->vn_cmp)(VP1, VP2)
  153. #define VOP_REALVP(VP, VPP)        (*(VP)->v_op->vn_realvp)(VP, VPP)
  154. #define VOP_STRATEGY(BP)        (*(BP)->b_vp->v_op->vn_strategy)(BP)
  155. #define    VOP_PAGEIN(VP,M,O)        (*(VP)->v_op->vn_pagein)(VP,M,O)
  156. #define    VOP_PAGEOUT(VP,A,S,O)        (*(VP)->v_op->vn_pageout)(VP,A,S,O)
  157. #define    VOP_NLINKS(VP,L)        (*(VP)->v_op->vn_nlinks)(VP,L)
  158.  
  159. #if    NeXT
  160. #define    VOP_DEVBLOCKSIZE(VP)        (*(VP)->v_op->vn_devblocksize)(VP)
  161. #define    VOP_PREPAGEIN(VP,M,O)        (*(VP)->v_op->vn_prepagein)(VP,M,O)
  162. #define    VOP_APAGEOUT(VP,A,S,O)        (*(VP)->v_op->vn_apageout)(VP,A,S,O)
  163. #endif    NeXT
  164.  
  165. /*
  166.  * flags for above
  167.  */
  168. #define IO_UNIT        0x01        /* do io as atomic unit for VOP_RDWR */
  169. #define IO_APPEND    0x02        /* append write for VOP_RDWR */
  170. #define IO_SYNC        0x04        /* sync io for VOP_RDWR */
  171. #define LOOKUP_DIR    0x08        /* want parent dir. vnode, VOP_LOOKUP */
  172.  
  173. #endif
  174.  
  175.  
  176. /*
  177.  * Vnode attributes.  A field value of -1
  178.  * represents a field whose value is unavailable
  179.  * (getattr) or which is not to be changed (setattr).
  180.  */
  181. struct vattr {
  182.     enum vtype    va_type;    /* vnode type (for create) */
  183.     u_short        va_mode;    /* files access mode and type */
  184.     uid_t        va_uid;        /* owner user id */
  185.     gid_t        va_gid;        /* owner group id */
  186.     long        va_fsid;    /* file system id (dev for now) */
  187.     long        va_nodeid;    /* node id */
  188.     short        va_nlink;    /* number of references to file */
  189.     u_long        va_size;    /* file size in bytes (quad?) */
  190.     long        va_blocksize;    /* blocksize preferred for i/o */
  191.     struct timeval    va_atime;    /* time of last access */
  192.     struct timeval    va_mtime;    /* time of last modification */
  193.     struct timeval    va_ctime;    /* time file ``created */
  194.     dev_t        va_rdev;    /* device the file represents */
  195.     long        va_blocks;    /* number of STAT_BSIZE blocks held */
  196. };
  197.  
  198. /*
  199.  *  Modes. Some values same as Ixxx entries from inode.h for now
  200.  */
  201. #define    VSUID    04000        /* set user id on execution */
  202. #define    VSGID    02000        /* set group id on execution */
  203. #define VSVTX    01000        /* save swapped text even after use */
  204. #define    VREAD    0400        /* read, write, execute permissions */
  205. #define    VWRITE    0200
  206. #define    VEXEC    0100
  207.  
  208. #ifdef KERNEL
  209. /*
  210.  * public vnode manipulation functions
  211.  */
  212. extern int vn_open();            /* open vnode */
  213. extern int vn_create();            /* creat/mkdir vnode */
  214. extern int vn_rdwr();            /* read or write vnode */
  215. extern int vn_close();            /* close vnode */
  216. extern void vn_rele();            /* release vnode */
  217. extern int vn_link();            /* make hard link */
  218. extern int vn_rename();            /* rename (move) */
  219. extern int vn_remove();            /* remove/rmdir */
  220. extern void vattr_null();        /* set attributes to null */
  221. extern int getvnodefp();        /* get fp from vnode fd */
  222.  
  223. #define VN_HOLD(VP)    { \
  224.     (VP)->v_count++; \
  225. }
  226.  
  227. #define VN_RELE(VP)    { \
  228.     vn_rele(VP); \
  229. }
  230.  
  231. #define VN_INIT(VP, VFSP, TYPE, DEV)    { \
  232.     (VP)->v_flag = 0; \
  233.     (VP)->v_count = 1; \
  234.     (VP)->v_shlockc = (VP)->v_exlockc = 0; \
  235.     (VP)->v_vfsp = (VFSP); \
  236.     (VP)->v_type = (TYPE); \
  237.     (VP)->v_rdev = (DEV); \
  238.     (VP)->v_socket = 0; \
  239.     timerclear(&(VP)->v_vfstime); \
  240. }
  241.  
  242. /*
  243.  * Compare two vnodes for equality.
  244.  * This macro should always be used,
  245.  * rather than calling VOP_CMP directly.
  246.  */
  247. #define VN_CMP(VP1,VP2)        ((VP1) == (VP2) ? 1 : \
  248.     ((VP1) && (VP2) && ((VP1)->v_op == (VP2)->v_op) ? VOP_CMP(VP1,VP2) : 0))
  249.  
  250. /*
  251.  * flags for above
  252.  */
  253. enum rm        { FILE, DIRECTORY };        /* rmdir or rm (remove) */
  254. enum symfollow    { NO_FOLLOW, FOLLOW_LINK };    /* follow symlinks (lookuppn) */
  255. enum vcexcl    { NONEXCL, EXCL};        /* (non)excl create (create) */
  256.  
  257. /*
  258.  * Global vnode data.
  259.  */
  260. extern struct vnode    *rootdir;        /* root (i.e. "/") vnode */
  261. extern enum vtype    mftovt_tab[];
  262. #define    MFMT        0170000            /* type of file */
  263. #define MFTOVT(M)    (mftovt_tab[((M) & MFMT) >> 13])
  264.  
  265. #endif
  266.  
  267. #endif _VNODE_H_
  268.